
data$forcing = as.integer(as.Date("1982-11-07"))- as.integer(as.Date(data$dob))
data$Cutoff00 = ifelse(data$forcing >= 0, 1, 0)




################# DV: Vote 2016 ########################

ivmod1_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                               downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)


ivmod1_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                             downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)
ivmod1_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                            downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2014 ##########################


ivmod2_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2012 ##########################

ivmod3_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2012_white", downstream_lag = "lag2012_white", bandwidth = 365, state.abbrev=NULL)
ivmod3_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2012_black", downstream_lag = "lag2012_black", bandwidth = 365, state.abbrev=NULL)
ivmod3_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2012_hispanic", downstream_lag = "lag2012_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Vote 2010 ##########################

ivmod4_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2010_white", downstream_lag = "lag2010_white", bandwidth = 365, state.abbrev=NULL)
ivmod4_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2010_black", downstream_lag = "lag2010_black", bandwidth = 365, state.abbrev=NULL)
ivmod4_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2010_hispanic", downstream_lag = "lag2010_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Democrat ##########################


ivmod5_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "democrat_white", downstream_lag = "lagdem_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "democrat_black", downstream_lag = "lagdem_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "democrat_hispanic", downstream_lag = "lagdem_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Republican ##########################

ivmod_rep_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "republican_white", downstream_lag = "lagrep_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "republican_black", downstream_lag = "lagrep_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "republican_hispanic", downstream_lag = "lagrep_hispanic", bandwidth = 365, state.abbrev=NULL)




##################### Registered ##########################

ivmod6_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "white", downstream_lag = "lagregistered_white", bandwidth = 365, state.abbrev=NULL)
ivmod6_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "black", downstream_lag = "lagregistered_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "hispanic", downstream_lag = "lagregistered_hispanic", bandwidth = 365, state.abbrev=NULL)
# 2008 voting

ivmod7_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2008_white", downstream_lag = "lag2008_white", bandwidth = 365, state.abbrev=NULL)


ivmod7_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2008_black", downstream_lag = "lag2008_black", bandwidth = 365, state.abbrev=NULL)
ivmod7_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2008_hispanic", downstream_lag = "lag2008_hispanic", bandwidth = 365, state.abbrev=NULL)

#2006 voting

ivmod8_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2006_white", downstream_lag = "lag2006_white", bandwidth = 365, state.abbrev=NULL)


ivmod8_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2006_black", downstream_lag = "lag2006_black", bandwidth = 365, state.abbrev=NULL)
ivmod8_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2006_hispanic", downstream_lag = "lag2006_hispanic", bandwidth = 365, state.abbrev=NULL)

#2004 voting

ivmod9_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2004_white", downstream_lag = "lag2004_white", bandwidth = 365, state.abbrev=NULL)


ivmod9_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2004_black", downstream_lag = "lag2004_black", bandwidth = 365, state.abbrev=NULL)
ivmod9_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2004_hispanic", downstream_lag = "lag2004_hispanic", bandwidth = 365, state.abbrev=NULL)


# 2002 voting

ivmod10_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_white", 
                                            downstream_voted = "vote.gen2002_white", downstream_lag = "lag2002_white", bandwidth = 365, state.abbrev=NULL)


ivmod10_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_black", 
                                            downstream_voted = "vote.gen2002_black", downstream_lag = "lag2002_black", bandwidth = 365, state.abbrev=NULL)
ivmod10_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff00", upstream_voted = "vote.gen2000_hispanic", 
                                               downstream_voted = "vote.gen2002_hispanic", downstream_lag = "lag2002_hispanic", bandwidth = 365, state.abbrev=NULL)


#################################################################################
######### Other cutoffs #########################################################
#################################################################################


data$forcing04 = as.integer(as.Date("1986-11-02"))- as.integer(as.Date(data$dob))

data$Cutoff04 = ifelse(data$forcing04 >=0, 1, 0)

###### 04 EV
################# DV: Vote 2016 ########################

ivmod_04_1_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)


ivmod_04_1_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_1_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2014 ##########################

ivmod_04_2_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04_2_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_2_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Vote 2012 ##########################

ivmod_04_3_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "vote.gen2012_white", downstream_lag = "lag2012_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04_3_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "vote.gen2012_black", downstream_lag = "lag2012_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_3_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "vote.gen2012_hispanic", downstream_lag = "lag2012_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Vote 2010 ##########################


ivmod_04_4_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "vote.gen2010_white", downstream_lag = "lag2010_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04_4_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "vote.gen2010_black", downstream_lag = "lag2010_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_4_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "vote.gen2010_hispanic", downstream_lag = "lag2010_hispanic", bandwidth = 365, state.abbrev=NULL)


##################### DV: Democrat ##########################


ivmod_04_5_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "democrat_white", downstream_lag = "lagdem_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04_5_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "democrat_black", downstream_lag = "lagdem_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_5_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "democrat_hispanic", downstream_lag = "lagdem_hispanic", bandwidth = 365, state.abbrev=NULL)



##################### DV: Republican ##########################


ivmod_04__rep_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                               downstream_voted = "republican_white", downstream_lag = "lagrep_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04__rep_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                               downstream_voted = "republican_black", downstream_lag = "lagrep_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04__rep_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                                  downstream_voted = "republican_hispanic", downstream_lag = "lagrep_hispanic", bandwidth = 365, state.abbrev=NULL)




##################### Registered ##########################


ivmod_04_6_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "white", downstream_lag = "lagregistered_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04_6_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "black", downstream_lag = "lagregistered_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_6_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "hispanic", downstream_lag = "lagregistered_hispanic", bandwidth = 365, state.abbrev=NULL)
# 2008 voting

ivmod_04_7_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "vote.gen2008_white", downstream_lag = "lag2008_white", bandwidth = 365, state.abbrev=NULL)


ivmod_04_7_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "vote.gen2008_black", downstream_lag = "lag2008_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_7_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "vote.gen2008_hispanic", downstream_lag = "lag2008_hispanic", bandwidth = 365, state.abbrev=NULL)

#2006 voting

ivmod_04_8_white = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_white", 
                                            downstream_voted = "vote.gen2006_white", downstream_lag = "lag2006_white", bandwidth = 365, state.abbrev=NULL)
ivmod_04_8_black = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_black", 
                                            downstream_voted = "vote.gen2006_black", downstream_lag = "lag2006_black", bandwidth = 365, state.abbrev=NULL)
ivmod_04_8_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing04", upstream_treat = "Cutoff04", upstream_voted = "vote.gen2004_hispanic", 
                                               downstream_voted = "vote.gen2006_hispanic", downstream_lag = "lag2006_hispanic", bandwidth = 365, state.abbrev=NULL)





rm(data)
filename = paste0("results_", state, "_other_elections.Rdata")
save.image(paste0("results/", filename))
rm(list=ls(pattern = "mod"))
